package magneticCave;

import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;
import javax.swing.border.LineBorder;

 
public class Cell extends JPanel
{
    private int token = Leaf.NO_ONE;
    private final int lineWidth = 1;
    
    public Cell(){
    	
    	setBorder(new LineBorder(Color.darkGray, lineWidth));
    //	addMouseListener(this);
    }
    
	
    public int getToken(){
    	this.repaint();
    	return token;
    }
    
    
    public void setToken(int token){
    	
    	this.token = token;
    	this.repaint();
    }
    
    @Override
    public int getWidth()
    {
    	return super.getWidth() + (lineWidth*2); 
    }
	
    @Override
    public int getHeight()
    {
    	return super.getHeight() + (lineWidth*2); 
    }
	
    protected void paintComponent(Graphics g)
    {
    	
    	super.paintComponent(g);
    	
    	// draw Black piece
    	if(token == Leaf.BLACK)
    		g.setColor(Color.black);
    				    			
    
    	// draw White piece
    	else if(token == Leaf.WHITE)
    		g.setColor(Color.white);	
    	
    	if(token != Leaf.NO_ONE)    	
    		g.fill3DRect( (int)((float)getWidth() * 0.1f), (int)((float)getHeight() * 0.1f), (int)((float)getWidth() * 0.85f), (int)((float)getHeight() * 0.85f), true);
    	
    }
}
